package com.wufun.overseas.utils;

import android.view.View;
import android.widget.ImageView;
import android.widget.TextView;

import java.util.List;

/**
 * Created by yangg on 2017/12/5.
 */

public class ForumUtil {


    /**
     * 社区，从图片地址获取图片宽高参数
     *
     * @param url
     * @return
     */
    public static Integer[] getImageSize(String url) {
        Integer[] ret = null;

        try {
            if (StringUtils.isNotEmpty(url)) {
                String temp = StringUtils.getNameNoExt(url);

                final String t1_split = "_size_";
                String[]     t1       = null;
                if (temp.contains(t1_split)) {
                    t1 = temp.split(t1_split);
                }

                final String t2_split = "_";
                String[]     t2       = null;
                if (null != t1 && t1.length > 1) {
                    if (t1[1].contains(t2_split)) {
                        t2 = t1[1].split(t2_split);
                    }
                }

                if (t2 != null && t2.length > 1
                        && StringUtils.isNotEmpty(t2[0]) && StringUtils.isNotEmpty(t2[1])) {
                    int width  = Integer.parseInt(t2[0]);
                    int height = Integer.parseInt(t2[1]);
                    ret = new Integer[2];
                    ret[0] = width;
                    ret[1] = height;
                }

            }
        } catch (Exception e) {
            e.printStackTrace();
        }

        return ret;
    }
    //region view样式设置
    public static void setTextViewValue(TextView textView, String value, String defValue) {
        if (StringUtils.isEmpty(value) || value.equals("null"))
            textView.setText(defValue);
        else
            textView.setText(value);
    }

    //region 头像,红名，金V点击事件
    public static void goSpec(final View... views) {
        if (views == null) return;
        View.OnClickListener listener = new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                goSpec(v);
            }
        };
        for (View view :
                views) {
            if (view != null)
                view.setOnClickListener(listener);
        }
    }
    public static void setShowLargeImagePreviwer(ImageView img, final int imgIndex, final List<String> rawList) {
        if (rawList == null || rawList.size() == 0) return;
        img.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                String[] strArr = new String[rawList.size()];
                rawList.toArray(strArr);
//                ForumUtil.goImagePagerActivity(v.getContext(), imgIndex, strArr);
            }
        });
    }
}
